home *** CD-ROM | disk | FTP | other *** search
/ Reverse Code Engineering RCE CD +sandman 2000 / ReverseCodeEngineeringRceCdsandman2000.iso / RCE / Ebooks / Thinking in C++ V2 / C17 / trim.h < prev    next >
Encoding:
C/C++ Source or Header  |  2000-05-25  |  539 b   |  20 lines

  1. //: C17:trim.h
  2. // From Thinking in C++, 2nd Edition
  3. // Available at http://www.BruceEckel.com
  4. // (c) Bruce Eckel 1999
  5. // Copyright notice in Copyright.txt
  6. #ifndef TRIM_H
  7. #define TRIM_H
  8. #include <string>
  9. // General tool to strip spaces from both ends:
  10. inline std::string trim(const std::string& s) {
  11.   if(s.length() == 0)
  12.     return s;
  13.   int b = s.find_first_not_of(" \t");
  14.   int e = s.find_last_not_of(" \t");
  15.   if(b == -1) // No non-spaces
  16.     return "";
  17.   return std::string(s, b, e - b + 1);
  18. }
  19. #endif // TRIM_H ///:~
  20.